package com.step.ems.component

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import coil.compose.SubcomposeAsyncImage
import com.step.ems.common.EventBus
import com.step.ems.common.NavBackEvent
import kotlinx.coroutines.launch
import net.engawapg.lib.zoomable.rememberZoomState
import net.engawapg.lib.zoomable.zoomable

@Composable
fun ImagePreviewScreen(url: String?) {
    val scope = rememberCoroutineScope()
    Box {
        SubcomposeAsyncImage(
            modifier = Modifier
                .fillMaxSize()
                .zoomable(rememberZoomState()),
            model = url,
            contentDescription = "Image",
            contentScale = ContentScale.Fit,
            loading = {
                Box(modifier = Modifier.matchParentSize()) {
                    Loading()
                }
            },
        )
        Box(
            modifier = Modifier
                .padding(horizontal = 10.dp, vertical = 60.dp)
                .clip(CircleShape)
                .background(Color(0x88EEEEEE))
                .clickable {
                    scope.launch {
                        EventBus.emit(NavBackEvent())
                    }
                }
                .padding(13.dp)

        ) {
            Icon(
                Icons.AutoMirrored.Filled.ArrowBack,
                contentDescription = null
            )
        }
    }
}